package com.huawei.hwCloudJs;

import android.util.Log;
import android.webkit.WebView;
import com.huawei.hms.framework.network.restclient.hianalytics.HianalyticsData;
import com.huawei.hwCloudJs.api.JsParam;
import com.huawei.hwCloudJs.c.a;
import com.huawei.hwCloudJs.core.JsCallback;
import com.huawei.hwCloudJs.service.jsmsg.NativeMsg;
import org.json.JSONException;
import org.json.JSONObject;

public class c {
    private static final String a = "JSUtils";

    public static JsParam a(JsParam jsParam, String str, String str2, String str3) {
        if (jsParam != null) {
            jsParam.setAppId(str);
            jsParam.setWebUrl(str2);
            jsParam.setBridgeId(str3);
        }
        return jsParam;
    }

    public static JSONObject a(String str) {
        try {
            return new JSONObject(str);
        } catch (JSONException e) {
            Log.e(a, "json2Object error");
            return null;
        }
    }

    public static void a(WebView webView) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("code", 0);
        } catch (JSONException e) {
            Log.e(a, "jsReady  put data error");
        }
        a(webView, a.a(a.b, jSONObject));
    }

    public static void a(WebView webView, int i) {
        a(webView, i, "");
    }

    public static void a(WebView webView, int i, String str) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("code", i);
            jSONObject.put(HianalyticsData.EXCEPTION_MESSAGE, str);
            a(webView, a.a(a.a, jSONObject));
        } catch (JSONException e) {
        }
    }

    public static void a(WebView webView, NativeMsg nativeMsg) {
        a(webView, a.a(nativeMsg));
    }

    public static void a(final WebView webView, final String str) {
        webView.post(new Runnable() {
            public void run() {
                webView.loadUrl(str);
            }
        });
    }

    public static void a(WebView webView, String str, int i, String str2) {
        new JsCallback(webView, str, str2).failure(i);
    }
}
